/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package main.java.org.dss.lm.admin.connection;

import java.sql.Connection;
import java.sql.SQLException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

/**
 *
 * @author 58835
 */

public class DatabaseConnection {

    private DataSource dataSource;
    private Connection dbCon =null;
    public DatabaseConnection(){
	try {
        Context init = new InitialContext();
        Context ctx = (Context) init.lookup("java:comp/env");
        dataSource = (DataSource)ctx.lookup("jdbc/dss_lm");
    }
    catch(NamingException e){
        e.printStackTrace();
    }
    }
    public Connection getDBConnection()throws SQLException{
        if(dbCon== null || dbCon.isClosed()){
            dbCon = dataSource.getConnection();
        }
        return dbCon;
    }
}
